#ifndef __POINT_H
#define __POINT_H

#include <cmath>
#include <iostream>

class Point {
 public:
	double x;
	double y;
	
 Point(double x, double y) : x(x), y(y)
	{
		
	}

	void set(double x, double y) {
		x = x;
		y = y;
	}

	const double& operator[] (int i) const
	{
		if (i==0)
			return x;
		if (i==1)
			return y;
		
		else {
			cerr << "Extracting values from points: You're doing it wrong. Returned value will be the x value." << endl;
			return x;
		}
	}
 
        void addInPlace(Point &p) {
		x += p.x;
		y += p.y;
	}

	static Point add(Point &p1, Point &p2) {
		Point result(0,0);
		result.addInPlace(p1);
		result.addInPlace(p2);
		return result;
	}

	Point operator+(const Point &rhs) const
	{
		return Point(x + rhs.x, y + rhs.y);
	}

	void subtractInPlace(Point &a) {
		x -= a.x;
		y -= a.y;
	}

	static Point subtract(Point &a, Point &b) {
		Point result(a);
		result.subtractInPlace(b);
		return result;
	}

	Point operator-(const Point &rhs) const
	{
		return Point(x - rhs.x, y - rhs.y);
	}

	void scale(int factor) {
		x*=factor;
		y*=factor;
	}

	Point operator*(const double &rhs) const
	{
		return Point(rhs*x, rhs*y);
	}


	double magnitude() const 
	{
		return sqrt(x*x + y*y);
	}

	void print() {
		std::cout << "(" << x << "," << y << ")" << std::endl;
	}
};

#endif
